package 泛型;


import java.util.List;

public class Foo {
    // 不能通过泛型实现方法重载,编译期就会报错
//    public void m1(List<String> list) {
//    }

    public void m1(List<Integer> list) {
        // java 中不允许创建泛型数组,编译期就会报错
        // List<String>[] ss = new List<String>[1];
        // 泛型不能用于类型判断,编译期就会报错 Inconvertible types; cannot cast 'java.util.List<java.lang.Integer>' to 'java.util.List<java.lang.String>'
        // System.out.println(list instanceof List<String>);
    }

    public <T> int m3(List<T> list, T t) {
        int count = 0;
        for (T item : list) {
//            if (item>t) {
//                count ++;
//            }
        }
        return count;
    }

    public <T extends Comparable<T>> int m4(List<T> list, T t) {
        int count = 0;
        for (T item : list) {
            if (item.compareTo(t) > 0) {
                count++;
            }
        }
        return count;
    }
    public <T> int m5(List<Comparable<T>> list, T t) {
        int count = 0;
        for (Comparable<T> item : list) {
            if (item.compareTo(t) > 0) {
                count++;
            }
        }
        return count;
    }
}
